#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>

//https://leetcode.cn/problems/find-pivot-index/submissions/

int pivotIndex(int* nums, int numsSize){
    int sumLeft = 0;
    int sumRight = 0;
    int mid = 0;
    for (int i = 1; i < numsSize; i++) {
        sumRight += nums[i];
    }
    for (int i = 0; i < numsSize; i++) {
        mid = i;
        if (sumLeft == sumRight) {
            return mid;
        } else if (sumLeft != sumRight && i < numsSize - 1) {
            sumRight -= nums[mid + 1];
            sumLeft += nums[i];
        }
    }
    return -1;
}

int main() {
    int arr[6] = {1, -1, 2};
    printf("%d", pivotIndex(arr, 3));
    return 0;
}